﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Text;
using System.Web.Security;
using Keiho.ServiceModel;

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class MembershipService : IMembershipService
{
    public ServiceResponse<bool> SignIn(MembershipInfo info)
    {
        if (info == null) throw new ArgumentNullException("info");

        try
        {
            bool isValidated = Membership.ValidateUser(info.UserId, info.Password);
            if (isValidated)
            {
                FormsAuthentication.SetAuthCookie(info.UserId, true);
            }
            return new ServiceResponse<bool> { Result = isValidated };
        }
        catch (Exception ex)
        {
            return new ServiceResponse<bool> { MessageType = MessageType.Error, Message = ex.Message };
        }
    }

    public ServiceResponse SignOut()
    {
        FormsAuthentication.SignOut();
        return new ServiceResponse();
    }
}
